work around file-io not setting locale encoding when opening a Handle
authorJoey Hess <joeyh@joeyh.name>
Mon, 15 Sep 2025 23:25:03 +0000 (19:25 -0400)
committerJoey Hess <joeyh@joeyh.name>
Mon, 15 Sep 2025 23:25:03 +0000 (19:25 -0400)
commit3e9807bc030d1cee243ab921590c91902f862e4f
tree7bb8427414d6500cd503c9a625bf36d2daf3416d
parent0e7d469f89afdf21807a8f2d64997a1f595f3d69
work around file-io not setting locale encoding when opening a Handle

Works around this bug https://github.com/haskell/file-io/issues/45

The fix is in Utility.FileIO.CloseOnExec because all use of file-io is
already wrapped through that module. Although perhaps that ought to be
refactored at this point.

I'd hope that file-io will eventually fix this bug, and also provide
CloseOnExec variants of its functions. That would allow depending on the
fixed version, and removing this ugly code.

Note that, functions like readFile that don't care about the encoding
due to reading/writing a ByteString were kept optimally fast by not
setting the encoding. This avoids an IORef read and write per open.

Sponsored-by: Graham Spencer
Utility/FileIO.hs
Utility/FileIO/CloseOnExec.hs
doc/bugs/yt-dlp_mojibake.mdwn